/**
* cw
 */

package io.cw.controller.background;

import io.cw.common.utils.Result;
import io.cw.dto.background.RoomEditDTO;
import io.cw.entity.background.ComplaintEntity;
import io.cw.entity.background.RoomEntity;
import io.cw.entity.background.UserInfoEntity;
import io.cw.entity.reservation.ReservationEntity;
import io.cw.service.impl.background.ComplaintService;
import io.cw.service.impl.background.RoomService;
import io.cw.service.impl.background.UserInfoService;
import io.cw.service.impl.reservation.ReservationRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 后台管理
 *
 * @author  cw
 */
@RestController
@RequestMapping("/backgrounp-manager")
@Api(tags = "后台管理", produces = MediaType.APPLICATION_JSON_VALUE)
public class BackgrounpController {

    @Autowired
    private RoomService roomService;

    @Autowired
    private UserInfoService userInfoService;

    @Autowired
    private ComplaintService complaintService;

    @Autowired
    private ReservationRecordService reservationRecordService;


    @PostMapping("/room/add")
    @ApiOperation("教室配置-新增")
    public Result add(@RequestBody @Valid RoomEntity roomDTO){
        roomService.add(roomDTO);
        return new Result<RoomEntity>().ok();
    }


    @PostMapping("/room/edit")
    @ApiOperation("教室配置-编辑")
    public Result edit(@RequestBody @Valid RoomEditDTO editDTO){
        roomService.edit(editDTO);
        return new Result<>().ok();
    }


    @GetMapping("/room/find-all")
    @ApiOperation("教室配置-全部列表")
    public Result<List<RoomEntity>> findListRoom(){
        return new Result<List<RoomEntity>>().ok(roomService.findAllList());
    }


    @GetMapping("/room/delete/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "教室ID", name = "id", paramType = "path", example = "1",dataTypeClass = String.class),
    })
    @ApiOperation("教室配置-删除")
    public Result delete(@PathVariable(value = "id", required = true) String id){
        roomService.delete(id);
        return new Result<>().ok();
    }


    @PostMapping("/user/find-all")
    @ApiOperation("用户管理-全部列表")
    public Result<List<UserInfoEntity>> findAllUser(){
        return new Result<List<UserInfoEntity>>().ok(userInfoService.findAllUser());
    }


    @GetMapping("/user/credit-score/edit/{id}/{score}")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户ID", name = "id", paramType = "path", example = "1",dataTypeClass = String.class),
            @ApiImplicitParam(value = "信用分值", name = "score", paramType = "path", example = "1",dataTypeClass = Integer.class),
    })
    @ApiOperation("用户管理-信用积分编辑")
    public Result editCreditScore(@PathVariable(value = "id") String uId, @PathVariable(value = "score") Integer score){
        userInfoService.editCreditScore(uId, score);
        return new Result<>().ok();
    }


    @GetMapping("/complaint/find-all")
    @ApiOperation("投诉管理-全部列表")
    public Result<List<ComplaintEntity>> findAllComplaint(){
        return new Result<List<ComplaintEntity>>().ok(complaintService.findAll());
    }


    @PostMapping("/complaint/handle/{id}/{score}")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "投诉记录ID", name = "id", paramType = "path", example = "1",dataTypeClass = String.class),
            @ApiImplicitParam(value = "信用分值", name = "score", paramType = "path", example = "1",dataTypeClass = Integer.class),
    })
    @ApiOperation("投诉管理-处理")
    public Result handleComplaint(@PathVariable(value = "id") String id, @PathVariable(value = "score") Integer score){
        complaintService.handleComplaint(id, score);
        return new Result<>().ok();
    }


    @GetMapping("/reservation/find/{keyWord}")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "手机号/教室编号", name = "keyWord", paramType = "path", example = "1",dataTypeClass = String.class),
    })
    @ApiOperation("预约管理-列表")
    public Result<List<ReservationEntity>> findAllReservation(@PathVariable(value = "keyWord",required = false) String keyWord){
        return new Result<List<ReservationEntity>>().ok(reservationRecordService.findAll(keyWord));
    }


    @PostMapping("/reservation/sign-in/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "预约ID", name = "id", paramType = "path", example = "1",dataTypeClass = String.class),
    })
    @ApiOperation("预约管理-签到")
    public Result signIn(@PathVariable(value = "id") String id) throws Exception {
        reservationRecordService.signIn(id);
        return new Result<>().ok();
    }

}